package com.xxx.seckill.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: xxx
 * @Date: 2023/1/9 20:41
 * @Description: RabbitMq配置-Direct模式
 */
@Configuration
public class RabbitMQDirectConfig {
    
    private static final String QUEUE01="queue_direct01";
    private static final String QUEUE02="queue_direct02";
    private static final String EXCHANGE="directExchange";
    private static final String ROUTINGKEY01="queue.red";
    private static final String ROUTINGKEY02="queue.green";


    /**
     * 1准备队列
     */
    @Bean
    public Queue queue01(){
        return new Queue(QUEUE01);
    }

    /**
     * 1准备队列
     */
    @Bean
    public Queue queue02(){
        return new Queue(QUEUE02);
    }

    /**
     * 准备direct交换机
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(EXCHANGE);
    }

    /**
     * 通过路由键绑定队列 交换机
     */
    @Bean
    public Binding binding001(){
        return BindingBuilder.bind(queue01()).to(directExchange()).with(ROUTINGKEY01);
    }

    /**
     * 通过路由键绑定队列 交换机
     */
    @Bean
    public Binding binding002(){
        return BindingBuilder.bind(queue02()).to(directExchange()).with(ROUTINGKEY02);
    }





}
